package com.manor.one.views;

import android.content.Context;
import android.graphics.drawable.Drawable;
import androidx.core.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.manor.common.Constants;
import com.manor.common.views.AbsViewHolder;
import com.manor.one.R;
import com.manor.one.activity.ChatBaseActivity;

/**
 * Created by cxf on 2018/10/9.
 * 直播间基类
 */

public abstract class AbsChatLiveViewHolder extends AbsViewHolder implements View.OnClickListener {

    private boolean mMute;
    private ImageView mMuteIcon;//静音
    private Drawable mMuteDrawable;
    private Drawable mUnMuteDrawable;
    private boolean mHands;
    private ImageView mHandsIcon;//免提
    private Drawable mHandsDrawable;
    private Drawable mUnHandsDrawable;
    protected int mChatType;

    public AbsChatLiveViewHolder(Context context, ViewGroup parentView) {
        super(context, parentView);
    }

    public AbsChatLiveViewHolder(Context context, ViewGroup parentView, Object... args) {
        super(context, parentView, args);
    }


    @Override
    protected void processArguments(Object... args) {
        mChatType = (int) args[0];
    }

    @Override
    public void init() {
        if (mChatType == Constants.CHAT_TYPE_VIDEO) {
            findViewById(R.id.btn_beauty).setOnClickListener(this);
            findViewById(R.id.btn_camera_switch).setOnClickListener(this);

            //  TODO 暂时隐藏美颜
            //  TODO 暂时隐藏美颜
            //  TODO 暂时隐藏美颜
            findViewById(R.id.btn_beauty).setVisibility(View.GONE);
        } else {
            findViewById(R.id.btn_beauty).setVisibility(View.INVISIBLE);
            findViewById(R.id.btn_camera_switch).setVisibility(View.INVISIBLE);
        }

        findViewById(R.id.btn_mute).setOnClickListener(this);
        findViewById(R.id.btn_hang_up).setOnClickListener(this);
        findViewById(R.id.btn_hands).setOnClickListener(this);
        mMuteIcon = (ImageView) findViewById(R.id.mute_icon);//静音
        mMuteDrawable = ContextCompat.getDrawable(mContext, R.mipmap.o_chat_mute_1);
        mUnMuteDrawable = ContextCompat.getDrawable(mContext, R.mipmap.o_chat_mute_0);
        //btn_hands hands_icon
        mHandsIcon = (ImageView) findViewById(R.id.hands_icon);//免提
        mHandsDrawable = ContextCompat.getDrawable(mContext, R.mipmap.ic_hands_free_pre);
        mUnHandsDrawable = ContextCompat.getDrawable(mContext, R.mipmap.ic_hands_free_nor);
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.btn_beauty) {
            ((ChatBaseActivity) mContext).beauty();
        } else if (i == R.id.btn_mute) {
            toggleMute();
        } else if (i == R.id.btn_hang_up) {
            ((ChatBaseActivity) mContext).hangUpChat();
        } else if (i == R.id.btn_camera_switch) {
            ((ChatBaseActivity) mContext).switchCamera();
        }else if (i == R.id.btn_hands) {
            toggleHands();
        }
    }


    private void toggleMute() {
        mMute = !mMute;
        ((ChatBaseActivity) mContext).setMute(mMute);
        if (mMuteIcon != null) {
            mMuteIcon.setImageDrawable(mMute ? mMuteDrawable : mUnMuteDrawable);
        }
    }

    private void toggleHands() {
        mHands = !mHands;
        ((ChatBaseActivity) mContext).setHands(mHands);
        if (mHandsIcon != null) {
            mHandsIcon.setImageDrawable(mHands ? mHandsDrawable : mUnHandsDrawable);
        }
    }

    public void show(){
        if (mContentView != null) {
            mContentView.setVisibility(View.VISIBLE);
        }
    }

    public void hide(){
        if (mContentView != null) {
            mContentView.setVisibility(View.GONE);
        }
    }

}
